package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shopping")

public class HomePageController {

    @Reference(timeout = 3000,check = false)
    IHomeService homeService;

    @Reference(timeout = 3000,check = false)
    IContentService contentService;

    @RequestMapping("/homepage")
    @Anoymous
    public ResponseData homePage() {

        HomePageResponse homepage = homeService.homepage();

        if (!ShoppingRetCode.SUCCESS.getCode().equals(homepage.getCode())) {
            return new ResponseUtil<>().setErrorMsg(homepage.getMsg());
        }
        return new ResponseUtil<>().setData(homepage.getPanelContentItemDtos());
    }


    @RequestMapping("/navigation")
    @Anoymous
    public ResponseData navigation() {
        NavListResponse navListResponse = contentService.queryNavList();

        if (!ShoppingRetCode.SUCCESS.getCode().equals(navListResponse.getCode())) {
            return new ResponseUtil<>().setErrorMsg(navListResponse.getMsg());
        }
        return new ResponseUtil<>().setData(navListResponse.getPannelContentDtos());
    }
}
